package com.liujit.standard.basis.admin.controller;

import com.liujit.standard.basis.admin.domain.result.LoginInfoResult;
import com.liujit.standard.basis.admin.util.ApiUtil;
import com.liujit.standard.basis.admin.domain.params.LoginParam;
import com.liujit.standard.basis.admin.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @description: 登录
 * @author: liujun
 * @create: 2021/3/24 9:29 下午
 **/
@Api(tags = "登录")
@RestController
@RequestMapping("/admin")
public class SysLoginController {

    @Resource
    private SysUserService sysUserService;

    @ApiOperation(value = "管理后台登录")
    @PostMapping("/login")
    @ApiImplicitParams({@ApiImplicitParam(name = "LoginParam", value = "登录参数")})
    public String login(@RequestBody @Valid LoginParam param) {
        String res = sysUserService.login(param);
        return res;
    }

    @ApiOperation(value = "获取用户信息")
    @GetMapping("/info")
    public LoginInfoResult info() {
        return sysUserService.info();
    }

    @ApiOperation(value = "退出", notes = "退出")
    @PostMapping("/logout")
    public Integer logout() {
        ApiUtil.removeToken();
        return 1;
    }
}